home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Collections: Camelot
/
Camelot 098 (1990-12)(Swedish User Group of Amiga)(SE)(PD)[WB].zip
/
Camelot 098 (1990-12)(Swedish User Group of Amiga)(SE)(PD)[WB].adf
/
XLisp-Stat
/
Functions
/
tour.lsp
< prev
next >
Wrap
Lisp/Scheme
|
1990-10-11
|
3KB
|
76 lines
; book pp.323-328
(defproto tour-mixin '(tour-count tour-trans))
(defmeth tour-mixin :do-idle () (send self :tour-step))
(defmeth tour-mixin :tour-step ()
(when (< (slot-value 'tour-count) 0)
(flet ((sphere-rand (m)
(let* ((x (normal-rand m))
(nx2 (sum (^ x 2))))
(if (< 0 nx2)
(/ x (sqrt nx2))
(/ (repeat 1 m) (sqrt m))))))
(let* ((m (send self :num-variables))
(angle (send self :angle))
(max (+ 1 (abs (floor (/ pi (* 2 angle)))))))
(setf (slot-value 'tour-count) (random max))
(setf (slot-value 'tour-trans)
(make-rotation (sphere-rand m)
(sphere-rand m)
angle)))))
(send self :apply-transformation (slot-value 'tour-trans))
(setf (slot-value 'tour-count)
(- (slot-value 'tour-count) 1)))
(send tour-mixin :slot-value 'tour-count -1)
(defmeth tour-mixin :tour-on (&rest args)
(apply #'send self :idle-on args))
(defproto tour-item-proto '(graph) () menu-item-proto)
(defmeth tour-item-proto :isnew (graph)
(call-next-method "Touring")
(setf (slot-value 'graph) graph))
(defmeth tour-item-proto :graph () (slot-value 'graph))
(defmeth tour-item-proto :update ()
(let ((graph (send self :graph)))
(send self :mark (send graph :tour-on))))
(defmeth tour-item-proto :do-action ()
(let* ((graph (send self :graph))
(is-on (send graph :tour-on)))
(send graph :tour-on (not is-on))))
(defmeth tour-mixin :menu-template ()
(append (call-next-method)
(list (send tour-item-proto :new self))))
(defproto spin-tour-proto () () (list tour-mixin spin-proto))
(send spin-tour-proto :title "Grand Tour")
(send spin-tour-proto :menu-title "Tour")
(defun tour-plot (data &rest args &key point-labels)
(let ((graph (apply #'send spin-tour-proto :new
(length data) args)))
(if point-labels
(send graph :add-points
data :point-labels point-labels :draw nil)
(send graph :add-points data :draw nil))
(send graph :adjust-to-data :draw nil)
graph))
(defproto hist-tour-proto '(angle) () (list tour-mixin histogram-proto))
(defmeth hist-tour-proto :angle (&optional new)
(if new (setf (slot-value 'angle) new))
(slot-value 'angle))
(send hist-tour-proto :angle .1)
(send hist-tour-proto :scale-type 'variable)
(send hist-tour-proto :title "Histogram Tour")
(send hist-tour-proto :menu-title "Tour")
(defun histogram-tour (data &rest args &key point-labels)
(let ((graph (apply #'send hist-tour-proto :new
(length data) :draw nil args)))
(if point-labels
(send graph :add-points
data :point-labels point-labels :draw nil)
(send graph :add-points data :draw nil))
(send graph :adjust-to-data :draw nil)
graph))